import { createElement, HTMLAttributes, type FC } from 'react';
import classNames from 'classnames';
import { tableRowDefaultProps } from './defaultProps';
import type { TableRowOptions } from './type';

export interface TableRowProps extends TableRowOptions, Omit<HTMLAttributes<HTMLTableRowElement>, 'color'> {}

const TableRow: FC<TableRowProps> = (props) => {
  const {
    className,
    color,
    active,
    disabled,
    marked,
    colored,
    textAlign,
    verticalAlign,
    children,
    forwardedRef,
    ...tableRowProps
  } = props;

  return createElement(
    'tr',
    {
      ref: forwardedRef,
      className: classNames(
        { active, disabled },
        color,
        colored,
        { colored },
        marked?.position,
        marked?.color,
        { marked },
        textAlign,
        { aligned: textAlign },
        verticalAlign,
        { aligned: verticalAlign },
        className,
      ),
      ...tableRowProps,
    },
    children,
  );
};

TableRow.displayName = 'TableRow';
TableRow.defaultProps = tableRowDefaultProps;

export default TableRow;
